package com.itheima.tliaswebmanagement.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.tliaswebmanagement.mapper.StudentMapper;
import com.itheima.tliaswebmanagement.pojo.common.PageResult;
import com.itheima.tliaswebmanagement.pojo.dto.EmpPageQueryDTO;
import com.itheima.tliaswebmanagement.pojo.dto.StudentPageQueryDTO;
import com.itheima.tliaswebmanagement.pojo.entity.Student;
import com.itheima.tliaswebmanagement.pojo.vo.EmpVO;
import com.itheima.tliaswebmanagement.pojo.vo.StudentVO;
import com.itheima.tliaswebmanagement.service.StudentService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Description StudentServiceImpl
 * @Author ziguan ling
 * @Date 2025--01--20
 */
@Slf4j
@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public PageResult<StudentVO> studentListQuery_s(StudentPageQueryDTO studentPageQueryDTO) {

        PageHelper.startPage(studentPageQueryDTO.getPage(), studentPageQueryDTO.getPageSize());

        Page<StudentVO> pageResult = (Page<StudentVO>) studentMapper.studentListQuery_d(studentPageQueryDTO);

        PageResult<StudentVO> pageResult1 = new PageResult<>(pageResult.getTotal(), pageResult.getResult());

        return pageResult1;
    }

    @Override
    public void addStudent_s(Student student) {
        log.info("添加学员:{}", student);
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.addStudent_d(student);
    }

    @Override
    public StudentVO queryById_s(Integer id) {
        log.info("根据id查询{}", id);
        StudentVO studentVO = studentMapper.queryById_d(id);
        return studentVO;
    }

    @Override
    public void updateStudent_s(Student student) {
        log.info("修改学员:{}", student);
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.updateStudent_d(student);
    }

    @Override
    public void removeBatchStudent_s(List<Integer> ids) {
        log.info("批量删除学员:{}", ids);
        studentMapper.removeBatchStudent_d(ids);
    }

    @Override
    public void violation_s(Integer id, Integer score) {
        log.info("违规处理:{}{}",id,score );
        studentMapper.violation_d(id, score);
    }
}
